package cn.b.sky.shop.activiti.listener;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultTaskListener implements TaskListener {
  /** 
  * @Fields serialVersionUID : 
  * @creator     :lidapeng
  */
  private static final long serialVersionUID = 1L;

  private static final Logger LOGGER= LoggerFactory.getLogger(DefaultTaskListener.class);

  @Override
  public void notify(DelegateTask delegateTask) {
    String eventName = delegateTask.getEventName();

    if ("create".equals(eventName)) {
      try {
        this.onCreate(delegateTask);
      } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
      }
    }

    if ("assignment".equals(eventName)) {
      try {
        this.onAssignment(delegateTask);
      } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
      }
    }

    if ("complete".equals(eventName)) {
      try {
        this.onComplete(delegateTask);
      } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
      }
    }

    if ("delete".equals(eventName)) {
      try {
        this.onDelete(delegateTask);
      } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
      }
    }

    ((TaskEntity) delegateTask).setEventName(eventName);
  }

  public void onCreate(DelegateTask delegateTask) {
    // Do nothing
  }

  public void onAssignment(DelegateTask delegateTask) {
    // Do nothing
  }

  public void onComplete(DelegateTask delegateTask) {
    // Do nothing
  }

  public void onDelete(DelegateTask delegateTask) {
    // Do nothing
  }
}
